/**
* @file      led.c
* @author    Supachai Vorapojpisut
* @version   1.0
* @date      November 30, 2014
* @brief     On-board LED module.
*/

/* Includes -----------------------------------------------------------------------*/
#include "led.h"

/* Private types ------------------------------------------------------------------*/
/* Private constants --------------------------------------------------------------*/
/* Private macro ------------------------------------------------------------------*/
/* Private variables --------------------------------------------------------------*/
/* Private function prototypes ----------------------------------------------------*/
/* Private functions --------------------------------------------------------------*/

/**
* @brief    Configure LEDs on STM32F4 Discovery board
*/
void LED_config(void)
{
    GPIO_InitTypeDef gpio_init_struct;
    
    // Enable GPIOD
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    
	// Configure LED pins to digital output (01), push-pull (0), 50-MHz (10), pull-up (01)
	gpio_init_struct.GPIO_Mode = GPIO_Mode_OUT;
	gpio_init_struct.GPIO_OType = GPIO_OType_PP;
	gpio_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
	gpio_init_struct.GPIO_PuPd = GPIO_PuPd_UP;
	gpio_init_struct.GPIO_Pin = ORANGE_LED;
	GPIO_Init(GPIOD, &gpio_init_struct);
    
	gpio_init_struct.GPIO_Pin = GREEN_LED;
	GPIO_Init(GPIOD, &gpio_init_struct);    

	gpio_init_struct.GPIO_Pin = RED_LED;
	GPIO_Init(GPIOD, &gpio_init_struct);

	gpio_init_struct.GPIO_Pin = BLUE_LED;
	GPIO_Init(GPIOD, &gpio_init_struct);
}


/** 
* @brief    Turn ON specific LED
* @param    led     LED to turn on
*/
void LED_on(uint16_t led)
{
    GPIO_WriteBit(GPIOD, led, Bit_SET);
}


/** 
* @brief    Turn OFF specific LED
* @param    led     LED to turn off
*/
void LED_off(uint16_t led)
{
    GPIO_WriteBit(GPIOD, led, Bit_RESET);
}
